﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GSLMS.Core;

namespace GSLMS.WebAPP.Areas.System.Controllers.Module
{
    public class ModuleController : AdminBaseController
    {
        List<GSLMS.Entity.Module> GetModuleList()
        {
            List<GSLMS.Entity.Module> moduleList = HelperCommon.GetModulesFromXML();// serviceModule.GetAll(base.SearchParma);
            HttpContext.Cache["moduleList"] = moduleList;
            return moduleList;
        }
        public ActionResult Index()
        {
            return View(GetModuleList());
        }

        [HttpPost]
        public string Index(FormCollection collection)
        {
            try
            {
                var moduleList = HttpContext.Cache["moduleList"] as List<GSLMS.Entity.Module>;
                var retult = false;
                if (moduleList != null && moduleList.Count > 0)
                {
                    retult = serviceModule.SaveAll(moduleList);

                }
                if (retult)
                {
                    ajaxStr = string.Format(ajaxStr, 200, ResourceManager.SaveSuccess, navTabId, "", "");
                }
                else
                {
                    ajaxStr = string.Format(ajaxStr, 300, ResourceManager.SaveFail, navTabId, "", "");
                }
            }
            catch (Exception ex)
            {
                base.ExceptionHand(ex);
                ajaxStr = string.Format(ajaxStr, 300, ResourceManager.SaveFail, navTabId, "", "");
            }
            return "{" + ajaxStr + "}";
        }
    }
}
